﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class AddUpdateFaq : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Setup CKEditor gọi CKFinder khi thêm Image
        CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
        _FileBrowser.BasePath = "AdminTools/ckfinder/";
        _FileBrowser.SetupCKEditor(ckeAnswer);


        if (!Page.IsPostBack)
        {
            load_RecordStatus();

            if (Request.QueryString["id"] != null)
            {
                int iID = int.Parse(Request.QueryString["id"].ToString());
                load_Faq(iID);
            }
        }

    }

    public void load_RecordStatus()
    {
        ListItem item = new ListItem();

        item.Value = "True";
        item.Text = "Công bố";
        item.Selected = true;
        rdlRecordStatus.Items.Add(item);

        item = new ListItem();
        item.Value = "False";
        item.Text = "Chờ";
        rdlRecordStatus.Items.Add(item);
    }

    public void load_Faq(int iID)
    {
        DataSet dsNews = BusLogic.Faq.get_FAQ(iID);

        txtQuestion.Text = dsNews.Tables[0].Rows[0]["QUESTION"].ToString();                
        ckeAnswer.Text = dsNews.Tables[0].Rows[0]["ANSWER"].ToString();
        rdlRecordStatus.SelectedValue = dsNews.Tables[0].Rows[0]["RECORD_STATUS"].ToString();
    }

    protected void lbtSave_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == null)
        {            
            BusLogic.Faq.add_FAQ(txtQuestion.Text, ckeAnswer.Text, Boolean.Parse(rdlRecordStatus.SelectedValue));
        }
        else
        {
            int iID = int.Parse(Request.QueryString["id"].ToString());
            BusLogic.Faq.update_FAQ(iID, txtQuestion.Text, ckeAnswer.Text, Boolean.Parse(rdlRecordStatus.SelectedValue));
        }

        Response.Redirect("FaqManager.aspx");
    }
}
